﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ApartmentBillsManager.Start.Common
{
    public class BillPhase
    {
        //private DateTime _startDate;
        //public DateTime EndDate;
        //public List<Roommate> RelevantRoommates;
        //public decimal PartialAmount;

        private BillPhase() {}

        public BillPhase(DateTime startDate, DateTime endDate, List<Roommate> relevantRoommates, Bill bill)
        {
            StartDate = startDate;
            EndDate = endDate;
            RelevantRoommates = relevantRoommates;
            PartialAmount = GetPartialAmount(startDate, endDate, bill);
        }

        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public List<Roommate> RelevantRoommates { get; set; }
        public decimal PartialAmount { get; set; }

        public int TotalDays
        {
            get { return EndDate.Subtract(StartDate).Days + 1; }
        }

        private static decimal GetPartialAmount(DateTime phaseStartDate, DateTime phaseEndDate, Bill bill)
        {
            var amountPerDay = bill.Amount / bill.TotalDays;
            var totalDaysInPhase = phaseEndDate.Subtract(phaseStartDate).Days + 1;

            return Math.Round(amountPerDay * totalDaysInPhase, 2);
        }
    }
}
